var axios = require('axios');
var lib = require('../lib/index.js');
// console.log(process.env.http_proxy);

var proxys = [];
var i = 0;
//221.226.119.246

function myRequest(url, config) {
    let options = Object.assign({
        method: 'get',
        url:url,
        headers: {
            "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36",
            'Content-Type': 'application/x-www-form-urlencoded'
        }
    }, config);

    let promise = new Promise(function(resolve, reject) {
        axios(options).then(function(response) {
            resolve(response.data);
        }).catch(function(error) {
            reject('error:'+url);
        });
    });

    return promise;
}

async function application() {
    // let proxy = 'http://105.27.238.160:80';
    let proxy = proxys[i];
    let arr = proxy.split(':');
    console.log(arr);
    i++;

    //https://szbns.en.alibaba.com/contactinfo.html?spm=a2700.icbuShop.88.49.5f316a96F2nnMH
    var result = await myRequest('http://dev.kuaidaili.com/testproxy',{
        proxy: {
            host: arr[0],
            port: arr[1],
            auth: {
                username: '85135103',
                password: '6rlb59k3'
            }
        },
    });
    console.log(result);
}

async function getIps() {
    var result = await myRequest('http://dps.kdlapi.com/api/getdps/?orderid=999581297060957&num=20&pt=1&dedup=1&format=json&sep=1');
    proxys = result.data.proxy_list
    console.log(proxys);
    application();
}
getIps();
